package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

//练习练习List集方法：get()、set()、重载remove()、重载add()、subList()
//2. 对List集合排序：排Integer、排String、排Point----练习Lambda表达式使用
//3. 练习Set集去重操作
public class ListDemo {
    public static void main(String[] args) {

        List<Dog> list = new ArrayList<>();
        Dog d1 = new Dog("旺财", 2);
        Dog d2 = new Dog("小黑", 3);
        Dog d3 = new Dog("小白", 2);
        Dog d4 = new Dog("哮天犬", 99);
        Collections.addAll(list, d1, d2, d3);
        System.out.println(list);
        for (int i = 0; i < list.size(); i++) {
            Dog dog = list.get(i);
            dog.bark();
        }
        Iterator<Dog> it = list.iterator();
        while (it.hasNext()) {
            it.next().bark();
        }
        for (Dog dog : list) {
            dog.bark();
        }
        System.out.println("---------------------------");
        list.set(2, d4);
        System.out.println(list);
        System.out.println("---------------------------");
        Dog remove = list.remove(0);
        System.out.println(remove);
        System.out.println(list);
        System.out.println("---------------------------");
        list.add(0,d1);
        list.add(2,d3);
        System.out.println(list);
      /*  List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");

        String s = list.get(0);
        System.out.println(s);
//get方法是list集合中的
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        list.set(0, "哈利波特");
        for (String s1 : list) {
            System.out.println(s1);
        }
*/

    }
}
